<!--海外管理-出库管理-->
<template>
  <div class="page-container ">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />
    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>
    <!-- <detail_standard_outbound ref="detail_standard_outbound" /> -->
    <report_anomaly ref="report_anomaly" :orderTypeList="['OUTBOUND']" system="WMS" @afterSubmitSuccess="reload()" />
  </div>
</template>
<script>
import business_function from "@/common/business_function"



// import detail_standard_outbound from '@/component/wms/detail_standard_outbound.vue';

import report_anomaly from '@/component/dialog/report_anomaly.vue'


import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';


import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'standard>outbound_manage'
export default {
  title: "title_standard_outbound_manage",
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: { report_anomaly },
  data() {
    return {
      dialogCreateWavePlan: false,

      option: {
        search: {
          default: {
            ownerlessFlag: "N",
          },
          model: [
            { label: "label_outbound_code", key: "outOrderNo", },
            { label: "label_order_code", key: "omsOrderNo", },
            { label: "label_customer", key: "customerIds", type: "common_customer_choose", attrs: { multiple: true }, },
            { label: "label_sku", key: "skuId", type: "sku_selec_input" },

            { label: "label_outbound_status", key: "status", type: 'select', enum: 'OutboundOrderStatusEunm' },
            { label: 'label_is_create_waveplan', key: 'wavePlanFlag', type: 'select', enum: 'YesOrNoEnum' },
            {
              key: 'ullageFlag', label: 'label_is_allow_ullage_outbound', type: 'select', enum: 'YesOrNoEnum'
            },
            { label: "label_outbound_type", key: "type", fold: true, type: 'select', enum: 'OutboundOrderTypeEnum' },

            { label: "label_pms_supply", key: "supplierName", fold: true, },
            { label: "label_consignee_person_name", key: "consignee", fold: true, },
            { label: "label_consignee_person_phone", key: "consigneePhone", fold: true, },
            { label: "label_track_code", key: "trackNumber", fold: true, },
            { label: "label_is_create_picktask", key: "pickTaskFlag", fold: true, type: 'select', enum: 'YesOrNoEnum' },
            // { label: "label_outbound_date", key: "outboundDate", fold: true, type: 'date-picker' },
            // { label: "label_sku", key: "skuId", type: 'sku_selec_input', fold: true, },
            {
              label: "label_logistics", key: "logisticsId", type: 'select', fold: true,
              url: "/wms-api/base/WmsPmsProductRpc/selectTransportList.json",
              urlParams: { productType: "LAST_TRANSPORT" },
              option: { label: "productName", value: "id" }
            },
            {
              label: "label_outbound_date", key: 'outboundDate', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'outboundDateEndTime'
                const limitValue = data[limitKey]

                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false }
                  }}
                />)
              }

            },
            {
              label: "~", key: 'outboundDateEndTime', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'outboundDate'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }}
                  pickerOptions={{
                    disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false }
                  }}
                />)
              }
            },
            {
              label: "label_create_time", key: 'gmtCreateForm', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'gmtCreateTo'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_start_time"
                  attrs={{ type: 'datetime' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue < date.getTime()) : false } }}
                />)
              }

            },
            {
              label: "~", key: 'gmtCreateTo', fold: true, type: 'date-picker', attrs: { type: 'datetime' },
              render: (h, { data, item }) => {
                const value = data[item.key]
                const limitKey = 'gmtCreateForm'
                const limitValue = data[limitKey]
                return (<ex_super_input value={value} onInput={e => this.$set(data, item.key, e)} type="date-picker" placeholder="label_end_time"
                  attrs={{ type: 'datetime', 'default-time': '23:59:59' }} pickerOptions={{ disabledDate: date => { return limitValue ? (limitValue > date.getTime()) : false } }}
                />)
              }
            },

            { label: "label_exception_handle", key: "handleExceptionFlag", fold: true, type: 'select', enum: 'YesOrNoEnum', },
          ],
        },
        actionExtra: [
          { label: 'label_report_exception', attrs: { type: "primary" }, click: this.batch_submitOrderException },
          { label: 'label_outbound_confirm', auth: 'wms_overseas_outbound_confirm', attrs: { type: "primary" }, click: this.batch_confirmOrderOutbound },
          // { label: 'label_import', auth: 'wms_overseas_outbound_manage_import', attrs: { type: "primary" }, click: this.$noFunction },
          { label: 'label_export', auth: 'wms_overseas_outbound_manage_export', attrs: { type: "primary" }, click: this.exportExcel },
        ],
        table: {
          url: "/wms-api/outbound/OutboundOverseasOrderRpc/selectByPage.json",
          model: this.init_table_model(),
        },

      },
      selection: [],

    };
  },


  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            class: "desc_flex_row",
            column: 4, border: true, direction: 'vertical', labelClassName: 'flex_cell', contentClassName: 'flex_cell',
            model: [],
          },
        },
        { key: 'outOrderNo', label: 'label_outbound_code', 'show-overflow-tooltip': true, },
        { key: 'omsOrderNo', label: 'label_order_code', 'show-overflow-tooltip': true, },
        { key: 'customerName', label: 'label_customer_info', 'width': 120, 'show-overflow-tooltip': true, },
        { key: 'trackNumber', label: 'label_face_track_code', 'width': 140, },
        { key: 'logisticsName', label: 'label_logistics', 'width': 120, 'show-overflow-tooltip': true, },


        { key: 'bizType', label: 'label_business_type', 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "BizTypeEnum") },
        { key: 'outboundProductType', label: 'label_sku_outbound_request', 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "OutboundProductTypeEnum") },

        { key: 'skuCount', label: 'label_actual_outbound_count', 'width': 100, },
        { key: 'wavePlanFlag', label: 'label_is_create_waveplan', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum") },
        { key: 'pickTaskFlag', label: 'label_is_create_picktask', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum") },
        {
          key: 'outType', label: 'label_outbound_type', 'width': 120, 'show-overflow-tooltip': true,
          render: (h, s) => this.$renderText(h, s, { enum: 'OutboundOrderTypeEnum', valueClassMap: { "DESTROY_OUTBOUND": "color_danger" } })
        },
        {
          key: 'outStatus', label: 'label_outbound_status', 'width': 120, 'show-overflow-tooltip': true,
          render: (h, s) => this.$renderText(h, s, {
            enum: 'OutboundOrderStatusEunm', valueClassMap: {
              "COMPLETE_OUTBOUND": "color_success", "CANCELED": "color_info", "SHORT_PICKING": "color_danger",
            }
          }),
        },
        { key: 'ecPlatformName', label: 'label_ec_platform', 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "OmsOutboundOrderEcPlatformEnum") },
        { key: 'outboundMode', label: 'label_outbound_method', formatter: (r, c, v) => this.$enumShow(v, "OutboundOrderModeEnum"), 'width': 120, },

        { key: 'handleExceptionFlag', label: 'label_exception_handle', 'width': 100, formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum") },
        { key: 'exceptionReason', label: 'label_reason_abnormal', 'width': 100, 'show-overflow-tooltip': true, },
        {
          key: 'ullageFlag', label: 'label_is_allow_ullage_outbound', 'width': 100, 'show-overflow-tooltip': true,
          formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum")
        },
        { key: 'gmtCreate', label: 'label_create_time','width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: 'outDate', label: 'label_outbound_date', 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: "interceptStatus", label: "label_intercept_status", 'width': 120, 'show-overflow-tooltip': true, formatter: (r, c, v) => this.$enumShow(v, "OrderInterceptStatusEnum"), },
        { key: "interceptCause", label: "label_intercept_reason", 'width': 120, 'show-overflow-tooltip': true, },
        { key: "interceptTime", label: "label_intercept_order_time", 'width': 130, formatter: (r, c, v, i) => this.$dateFormat(v) },
        { key: "twicePutawayFlag", label: "label_is_second_put", 'width': 120, formatter: (r, c, v) => this.$enumShow(v, "YesOrNoEnum") },
        {
          type: 'operate', width: 160, fixed: "right", operate: [
            {
              type: 'more',
              items: [
                { label: 'label_view_detail', click: (row) => { this.clickDetail(row) } },

                {
                  label: 'label_report_exception',
                  // disabled: (row) => this.disabledException(row),
                  // click: (row) => this.submitOrderException([row])
                  click: (row) => this.reportAnomaly(row),
                },
                {
                  label: 'label_outbound_confirm', auth: 'wms_overseas_outbound_confirm',
                  disabled: this.disabledConfirmOrder,
                  click: (row) => this.confirmOrderOutbound([row])
                },
              ]
            }
          ]
        }
      ]
    },
    reportAnomaly(row) {
      this['$refs']['report_anomaly'].showNew({
        formDisabled: true,
        data: {
          customerName: row.customerName,
          customerCode: row.customerCode,
          customerId: row.customerId,
          orderType: 'OUTBOUND',
          orderNo: row.outOrderNo,
        },
        onlySetData: true,

      })
    },
    disabledException(row) {
      return !['SHORT_PICKING'].some(it => it == row.outStatus) || row.handleExceptionFlag == "Y"
    },
    disabledConfirmOrder(row) {
      return !['PARTIALLY_COMPLETED_OUTBOUND'].some(it => it == row.outStatus) ||
        row.handleExceptionFlag == "Y" || row.ullageFlag == "N"
    },


    clickDetail(row) {
      // let title = `${this.$tt('label_outbound_code')}:${row.outOrderNo}`
      // this.$refs['detail_standard_outbound'].show({ params: { id: row.id }, title })
      this.$router.push({ path: '/page/wms/overseas/outbound/outbound_detail', query: { code: row.outOrderNo, id: row.id, } })

    },

    batch_submitOrderException() {
      if (this.selection.length == 0) return this.$message.error(this.$tt('tip_please_select_order'))


      if (this.selection.some((row) => this.disabledException(row))) {
        let checkNoList = []
        this.selection.forEach(row => {
          if (this.disabledException(row)) checkNoList.push(row)
        })
        this.$msgbox_table({
          note: this.$tt('tip_part_order_status_error_no_operate'),
          tableProp: {
            data: checkNoList,
            model: [
              { key: 'outOrderNo', label: 'label_outbound_code' },
              { key: 'omsOrderNo', label: 'label_order_code' },
            ]
          }
        }, { type: 'warning' })
        return
      }

      this.submitOrderException(this.selection)
    },
    submitOrderException(_list) {
      this.$prompt(
        this.$tt('tip_count_please_input_submitExceptionReason', { count: _list.length }),
        this.$tt('label_tip'), {
        confirmButtonText: this.$tt('label_confirm'),
        cancelButtonText: this.$tt('label_cancel'),
        inputPlaceholder: this.$tt('tip_please_input_submitExceptionReason'),
        inputValidator: (value) => {
          if (_.isEmpty(value)) return this.$tt('tip_can_no_empty')
          return true
        },
        type: 'warning'
      }).then(({ value }) => {
        this.$ajax({
          url: "/wms-api/outbound/OutboundOverseasOrderRpc/submitOrderException.json",
          method: 'post', type: 'json',
          data: {
            orderSubmitList: _list.map(it => { return { outOrderNo: it.outOrderNo, reason: value } })
          },
          success: (res) => {
            this.reload()
          }
        })
      }).catch(() => {
      });
    },
    batch_confirmOrderOutbound() {
      if (this.selection.length == 0) return this.$message.error(this.$tt('tip_please_select_order'))


      if (this.selection.some((row) => this.disabledConfirmOrder(row))) {
        let checkNoList = []
        this.selection.forEach(row => {
          if (this.disabledConfirmOrder(row)) checkNoList.push(row)
        })
        this.$msgbox_table({
          note: this.$tt('tip_part_order_status_error_no_operate'),
          tableProp: {
            data: checkNoList,
            model: [
              { key: 'outOrderNo', label: 'label_outbound_code', 'min-width': 140, 'show-overflow-tooltip': true, },
              { key: 'omsOrderNo', label: 'label_order_code', 'min-width': 120, 'show-overflow-tooltip': true, },
              {
                key: 'outStatus', label: 'label_outbound_status', 'min-width': 120, 'show-overflow-tooltip': true,
                formatter: (r, c, v, i) => this.$enumShow(v, "OutboundOrderStatusEunm")
              },
              {
                key: 'handleExceptionFlag', label: 'label_exception_handle', 'min-width': 100, 'show-overflow-tooltip': true,
                formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum")
              },
              {
                key: 'ullageFlag', label: 'label_is_allow_ullage_outbound', 'min-width': 100, 'show-overflow-tooltip': true,
                formatter: (r, c, v, i) => this.$enumShow(v, "YesOrNoEnum")
              },
            ]
          }
        }, { type: 'warning', customClass: 'dialog_small' })
          .then(() => {

          }).catch(() => {
          });
        return
      }

      this.confirmOrderOutbound(this.selection)
    },
    confirmOrderOutbound(_list) {
      this.$prompt(this.$tt('tip_count_please_input_outboundConfirmReason', { count: _list.length }), this.$tt('label_tip'), {
        confirmButtonText: this.$tt('label_confirm'),
        cancelButtonText: this.$tt('label_cancel'),
        inputPlaceholder: this.$tt('tip_please_input_outboundConfirmReason'),
        inputValidator: (value) => {
          if (_.isEmpty(value)) return this.$tt('tip_can_no_empty')
          return true
        },
        type: 'warning'
      }).then(({ value }) => {
        this.$ajax({
          url: "/wms-api/outbound/OutboundOverseasOrderRpc/confirmOrderOutbound.json",
          method: 'post', type: 'json',
          data: {
            orderSubmitList: _list.map(it => { return { outOrderNo: it.outOrderNo, reason: value } })
          },
          success: (res) => {
            this.reload()
          }
        })
      }).catch(() => {
      });
    },
    exportExcel() {
      business_function.confirmOperateBaseSelectOrForm.call(this, {
        data: this.$refs.SuperTablePage.getSearchFormData(),
        model: this.option.search.model,
        selection: this.selection,
        callback: (selection, data) => {
          let params = {}
          if (!_.isEmpty(selection)) {
            params = {
              idList: selection.map(it => it.id)
            }
          } else {
            params = data
          }
          this.$functionCommon({
            url: "/wms-api/outbound/OutboundOverseasOrderRpc/exportOrderExcel.json",
            data: params,
          })
        }
      })
    },
  }
};

</script>
<style></style>
